package demo;
import java.util.SortedSet;
import java.util.TreeSet;

import datamodel.QMarketSummary;
import demo.util.MarketTypeFilters;
import demo.util.MarketsNameComparator;

public class EquivalentMarkets implements Comparable<EquivalentMarkets> {
	
	private SortedSet<QMarketSummary> mercadosEquivalentes = new TreeSet<QMarketSummary>(new MarketsNameComparator());
	private String eventPath;
	
	public EquivalentMarkets(){
		super();
	}
	
	public EquivalentMarkets(String evento){
		super();
		this.eventPath = evento;
	}
	
	public boolean addMarket(QMarketSummary market){
		boolean res = false;
		if (mercadosEquivalentes.isEmpty()){
			if (MarketTypeFilters.isNumberOfGoalsMarket(market) || MarketTypeFilters.isTotalGoalsMarket(market))
				res = mercadosEquivalentes.add(market);
		}
		else{
			for (QMarketSummary m:mercadosEquivalentes){
				if (MarketTypeFilters.areEquivalentMarkets(market, m) || MarketTypeFilters.isNumberOfGoalsMarket(market)){
					res = mercadosEquivalentes.add(market);
					break;
				}
			}
		}
		
		return res;
	}
	
	public SortedSet<QMarketSummary> getAllMarkets(){
		return mercadosEquivalentes;
	}
	
	public void setEvent(String eventPath){
		this.eventPath = eventPath;
	}
	
	public String getEvent(){
		return eventPath;
	}
	
	public boolean equals(Object o){
		boolean res = false;
		
		if(o instanceof EquivalentMarkets){
			EquivalentMarkets em = (EquivalentMarkets)o;
			res = em.getEvent().equals(this.getEvent());
		}
		return res;
	}

	@Override
	public int compareTo(EquivalentMarkets arg0) {
		return arg0.getEvent().compareTo(this.getEvent());
	}

}
